<?php
/** 初始化项目 */
require '../../app/app.php';
/** 初始化数据库 */
use app\util\Mysql;
$database = Mysql::init();

if (isset($_GET["tid"])) {
    $id = $_GET["tid"];
    header('Content-Type: application/json');
    $time = $database->select("text_main", ["created"], ["tid" => $id]);
    $time = $time[0]['created'];
    $date = new DateTime("@$time");
    $date->setTimezone(new DateTimeZone('Asia/Shanghai'));
    $date = $date->format('Y-m-d H:i:s'); //date整理结束
    $main = $database->select("text_main", ["main"], ["tid" => $id]);
    $main = $main[0]['main'];
    $main = htmlspecialchars_decode($main, ENT_COMPAT); //文章主题处理完成
    $creator = $database->select("text_main", ["creator"], ["tid" => $id]);
    $creator = $creator[0]['creator']; //作者处理完成
    $textname = $database->select("text_main", ["textname"], ["tid" => $id]);
    $textname = $textname[0]['textname']; //文章名处理完成
    $name = $database->select("more_file", ["name"], ["text_id" => $id]);
    $name = $name[0]['name']; //文件名处理完成
    $file_url = $database->select("more_file", ["file_url"], ["text_id" => $id]);
    $file_url = $file_url[0]['file_url']; //文章名处理完成
    $post_text = array("textname" => $textname, "main" => $main, "creator" => $creator, "created" => $date, "file_url" => $file_url, "name" => $name);
    $json = json_encode(array(
        'post_text' => $post_text
    ));
    echo $json;
}
